// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... using System; using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Serialization; namespace LargoCommon.Music { /// Harmonic interval. /// /// HarmonicInterval represents one formal interval, /// i.e. relation of two tones of the formal harmonic GSystem. /// Interval has assigned name, (formal) distance and values /// of continuity, impulse, potential influence and Similarity. [Serializable] [XmlRoot] public sealed class HarmonicInterval : MusicalInterval { #region Constructors /// Initializes a new instance of the HarmonicInterval class. Serializable. public HarmonicInterval() { } /// Initializes a new instance of the HarmonicInterval class. /// Harmonic system. /// Interval length. /// Weight of darkness. public HarmonicInterval(HarmonicSystem harmonicSystem, byte length, float weight) { Contract.Requires(harmonicSystem != null); //// if (harmonicSystem == null) { return; } this.HarmonicSystem = harmonicSystem; this.SystemLength = length; this.Weight = weight; this.FormalLength = harmonicSystem.FormalLength(this.SystemLength); this.Name = harmonicSystem.GuessNameForInterval(this.FormalLength); this.Ratio = harmonicSystem.RatioForInterval(this.SystemLength); this.Halftones = harmonicSystem.HalftonesForInterval(this.FormalLength); } /// Initializes a new instance of the HarmonicInterval class. /// Harmonic system. /// Fist element of system. /// Second element of system. public HarmonicInterval(HarmonicSystem harmonicSystem, byte elementFrom, byte elementTo) : base(harmonicSystem, elementFrom, elementTo) { Contract.Requires(harmonicSystem != null); } /// Initializes a new instance of the HarmonicInterval class. /// Harmonic system. /// First musical pitch. /// Second musical pitch. public HarmonicInterval(HarmonicSystem harmonicSystem, MusicalPitch givenPitch1, MusicalPitch givenPitch2) : base(harmonicSystem, givenPitch1, givenPitch2) { Contract.Requires(harmonicSystem != null); } /// Initializes a new instance of the HarmonicInterval class. /// Harmonic system. /// First melodic tone. /// Second melodic tone. public HarmonicInterval(HarmonicSystem harmonicSystem, MusicalTone tone1, MusicalTone tone2) : base(harmonicSystem, tone1, tone2) { Contract.Requires(harmonicSystem != null); Contract.Requires(tone1 != null); Contract.Requires(tone2 != null); } #endregion #region Properties /// Gets or sets length in halftones. /// Property description. public float Halftones { get; set; } /// Gets or sets name. /// Property description. public string Name { get; set; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.Append(string.Format(CultureInfo.InvariantCulture, "{0}/{1}\t", string.Format(CultureInfo.CurrentCulture.NumberFormat, "{0,3}", this.FormalLength), string.Format(CultureInfo.CurrentCulture.NumberFormat, "{0,12}", this.Name))); //// s.Append(this.StringOfProperties()); return s.ToString(); } #endregion } }